import React from 'react';
import { Select } from 'antd';

const { Option } = Select;

const SearchSelect = {
  transData: (values, name) => values[name],
  render: (item, onChange) => {
    const { selectConfig = {} } = item;
    const { optionValue = 'value', optionLabel = 'label', showSearch = true, mode } = selectConfig;
    const myChange = (v) => {
      onChange({ [item.name]: v }, item.name);
    };
    return (
      <Select
        className="search-form-item"
        placeholder="请选择"
        optionFilterProp="children"
        filterOption={(input, option) =>
          option.props.children.toLowerCase().indexOf(input.toLowerCase()) >= 0
        }
        onChange={myChange}
        allowClear
        mode={mode}
        showSearch={showSearch}
      >
        {selectConfig?.data?.map((option) => (
          <Option value={option[optionValue]} key={option[optionValue]}>
            {option[optionLabel]}
          </Option>
        ))}
      </Select>
    );
  },
};

export default SearchSelect;
